def main():
    def stringTest():
        str1="hello,world!"
        str2="abc123"
        print(str1.find("*"))
        print(str1.center(20,"*"))
    # stringTest()
    def listTest():
        list1=[1,"b","c",4]
        list2=['12','34','abc','ef']
        for v in list1:
            print(v,end=",")
        print()
        for index,item in enumerate(list1):
            print(f"{item},{index}",end=";")
        list2Sort=sorted(list2,key=len)
        list2Sort.sort(reverse=True)
        print(list2Sort)
        f = [x + y for x in 'ABCDE' for y in '1234567']
        print(f)
    listTest()
    def setTest():
        set1={1,2,3,4}
        set1.update([5,6])
        set1.update((7,8))
        set1.update({9,0})
        t=(1,2,'c','D',"D")
        print(set1)
        print(t)
    setTest()
    #列表list：有序、可重复、可更改元素
    #元组tuple：有序、可重复、不可更改元素
    #集合set：无序、不可重复、可更改元素
    #有序，是指可以索引访问，不是本身排序

    #字典的遍历，是遍历key
    def dictionaryTest():
        # 创建字典的字面量语法
        scores = {'骆昊': 95, '白元芳': 78, '狄仁杰': 82}
        print(scores)
        # 创建字典的构造器语法
        items1 = dict(one=1, two=2, three=3, four=4)
        # 通过zip函数将两个序列压成字典
        items2 = dict(zip(['a', 'b', 'c'], '123'))
        # 创建字典的推导式语法
        items3 = {num: num ** 2 for num in range(1, 10)}
        print(items1, items2, items3)
        # 通过键可以获取字典中对应的值
        print(scores['骆昊'])
        print(scores['狄仁杰'])
        for key in scores:
            print(f"{key}:{scores[key]}",end=",")
    import time
    import os
    def timeToShwo():
        content = '感觉不如原神。。。'
        counter=0
        while counter<20:
            # 清理屏幕上的输出
            os.system('cls')  # os.system('clear')
            print(content)
            # 休眠200毫秒
            time.sleep(0.2)
            content = content[1:] + content[0]
            counter+=1
    # timeToShwo()
    import random
    def getAutnCodeByLength(length):
        all_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
        end=len(all_chars)
        code=""
        for i in range(0,length):
            rintIndex=random.randint(0,end)
            code+=all_chars[rintIndex]
        print(code)
    # getAutnCodeByLength(int(input("随机生成验证码的长度")))
    def getFileLastName(fileName,has_dot=False):
        dotIndex = fileName.find(".")
        if not has_dot :
            dotIndex+=1
        lastName=""
        if 0 < dotIndex and dotIndex < len(fileName) - 1:
            lastName= fileName[dotIndex:]
        print(lastName)
    # getFileLastName("原神.exe",True)
    def getFirstAndSecondMax(arr):
        print(f"输入：{arr}最大：{sorted(arr)[-1]}，其次{sorted(arr)[-2]}")
    # getFirstAndSecondMax([1,2,5,3,100,8])
    def dayCountByDatestring(datestring):
        if "年" in datestring and "月" in datestring and "日" in datestring:
            yearIndex=datestring.find("年")
            monthIndex=datestring.find("月")
            dayIndex=datestring.find("日")
            year=int(datestring[0:yearIndex])
            month=int(datestring[yearIndex+1:monthIndex])
            day=int(datestring[monthIndex+1:dayIndex])
            counter=0
            isFullYear=False
            if year%4==0:
                isFullYear=True
            for i in range(1,month):
                temp=30
                if i != 2:
                    if i<8 and i%2>0:
                        temp=31
                    if i>=8 and i%2==0:
                        temp=31
                else:
                    temp=28
                counter+=temp
            if isFullYear and month>2:
                counter+=1
            counter+=day
            print(f"{datestring}是该年的第{counter}天。")
        else:
            print("非法的年月日字符串！")
    # dayCountByDatestring(input("请输入年月日字符串："))
    def YanghuiTriangle():
        #层是从0开始的，行是从1开始的
        num=int(input("请输入杨辉三角的行数："))
        triangleList=[[]]*num
        for row in range(num):
            triangleList[row]=[None]*(row+1)
            for col in range(row+1):
                if col==0 or col==row:
                    triangleList[row][col]=1
                else:
                    triangleList[row][col]=triangleList[row-1][col-1]+triangleList[row-1][col]

        for i in range(0,num):
            for j in range(0,num-i-1):
                print("",end=" ")
            for v in triangleList[i]:
                print(v,end=" ")
            print()
    # YanghuiTriangle()
if __name__=="__main__":
    main()